package com.gather.spring.service.cglib;


import com.gather.spring.retry.cglib.request.QueryUserCondition;
import com.gather.spring.retry.cglib.proxy.RetryConstant;
import com.gather.po.User;

/**
 * @author kxd
 * @date 2018/12/5 13:50
 * description:
 */
public class UserServiceRetryImpl implements UserService {
    @Override
    public User queryUser(QueryUserCondition condition) {
        int times = 0;
        OutService outService = new AlwaysFailOutServiceImpl();

        while (times < RetryConstant.MAX_TIMES) {
            try {
                outService.remoteCall();
            } catch (Exception e) {
                times++;
                if (times >= RetryConstant.MAX_TIMES) {
                    throw new RuntimeException(e);
                }
            }
        }
        return null;
    }
}
